package com.ucomm.talent.activity.detail;

import com.ucomm.talent.AppConfig;
import com.ucomm.talent.AppConstants;
import com.ucomm.talent.AppException;
import com.ucomm.talent.R;
import com.ucomm.talent.activity.IHeaderBarClickListener;
import com.ucomm.talent.common.DebugUtil;
import com.ucomm.talent.manager.DetailSearchManager;
import com.ucomm.talent.model.RecommendJobDetailInfo;
import com.ucomm.talent.model.RecommendedJobsInfo;
import com.ucomm.talent.widget.CustomProgressDialog;
import com.ucomm.talent.widget.MainHeaderBar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;

/**
 * 
 * @author Administrator
 * @Description:推荐职位详细界面
 *
 */
public class RecommendJobDetails extends Activity implements IHeaderBarClickListener{
	
	private CustomProgressDialog customProgressDialog;
	private MainHeaderBar mainHeaderBar;
	private DetailSearchManager detailSearchManager;
	private ViewStub detailsViewStub1;
	private ViewStub detailsViewStub2;
	private int id = 0;
	private TextView offerNum;
	private TextView salaryRange;
	private TextView workAge;
	private TextView workLoc;
	private TextView jobName;
	private TextView description;
	
	Handler mHandler = new Handler(){
        @Override
    public void handleMessage(Message msg) {
        int what = msg.what;
        DebugUtil.Log(RecommendJobDetails.this,"---------- " + customProgressDialog.toString());
        switch (what){
            case AppConstants.MsgStatus.MSG_ERROR:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                ((AppException)msg.obj).makeToast(RecommendJobDetails.this);
                break;
            case AppConstants.MsgStatus.MSG_SUCCUSS:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                //获取数据
                RecommendJobDetailInfo details = (RecommendJobDetailInfo) msg.obj;
                String salaryRangeText = null;
                String workAgeText = null;
                String workLocText = null;
                jobName.setText(details.getJobName());
                offerNum.setText(details.getWorkerNum()+"");
                if(AppConfig.comMap.size() != 0 && AppConfig.cityMap.size()!=0){
                	salaryRangeText = AppConfig.comMap.get(details.getSalaryRange());
                	workAgeText = AppConfig.comMap.get(details.getWorkAge());
                	workLocText = AppConfig.cityMap.get(details.getProvinceId()) + AppConfig.cityMap.get(details.getCityId());
                }
                salaryRange.setText(salaryRangeText);
                workAge.setText(workAgeText);
                workLoc.setText(workLocText);
                description.setText(details.getDescription());
                break;
            case AppConstants.MsgStatus.MSG_LOADING:
                if (customProgressDialog != null && !customProgressDialog.isShowing())
                    customProgressDialog.show();
                break;
            default:
                break;
        }
        super.handleMessage(msg);
    }
    };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recom_job_details);
		Intent i = getIntent();
		RecommendedJobsInfo info = (RecommendedJobsInfo) i.getSerializableExtra("info");
		id = info.getJobId();
		initView();
		customProgressDialog = new CustomProgressDialog(this);
        detailSearchManager = new DetailSearchManager(this, mHandler);
        final String url = AppConstants.RECOMMENDED_JOBS_DETAILS+id;
        detailSearchManager.searchDetailDataFromNetwork(url);
	}
	private void initView(){
		detailsViewStub1 = (ViewStub) findViewById(R.id.job_offer_details_vs1);
		detailsViewStub2 = (ViewStub) findViewById(R.id.job_offer_details_vs2);
		mainHeaderBar = (MainHeaderBar) findViewById(R.id.main_header_bar);
        mainHeaderBar.setBarClickListener(this);
        detailsViewStub1.inflate();
        offerNum = (TextView) findViewById(R.id.offer_num);
        salaryRange = (TextView) findViewById(R.id.salary_range);
        workAge = (TextView) findViewById(R.id.work_age);
        workLoc = (TextView) findViewById(R.id.work_location);
        jobName = (TextView) findViewById(R.id.job_name);
        detailsViewStub2.inflate();
        description = (TextView) findViewById(R.id.detail_description);
	}
	@Override
	public void onBackButtOnClick(View view) {
		// TODO Auto-generated method stub
		finish();
	}

	@Override
	public void onExitButtonOnClick(View view) {
		// TODO Auto-generated method stub
		
	}

}
